<?php

class publicacionesActions extends sfActions {

    public function preExecute()
    {
         $this->getUser()->setAttribute('s_menu', 'publicaciones');
    }

      public function executeRevista(sfWebRequest $request){
        $titulo=$request->getParameter('titulo');
        $autor=$request->getParameter('autor');
        $opcion=$request->getParameter('opcion');

        if($opcion==3)
        {
    
         $c = new Criteria();
         $c->add(PublicationsPeer::ENABLED,1);
        if($titulo!=""){
            $c->add(PublicationsPeer::TITLE, "%".$titulo."%", Criteria::LIKE);
        }
        if($autor!=""){
            $c->add(PublicationsPeer::AUTHOR, "%".$autor."%", Criteria::LIKE);
        }
        $c->add(PublicationsPeer::ENABLED,1);
        $c->addDescendingOrderByColumn(PublicationsPeer::RELEASE_DATE);
        $c->addAscendingOrderByColumn(PublicationsPeer::CREATED_AT);

        $pager = new sfPropelPager('Publications', 14);
        $pager->setCriteria($c);
        $pager->setPage($request->getParameter('page',4 ));
        $pager->init();
        $this->pager = $pager;

        $maxpag=$pager->getMaxPerPage();
        $this->max=$maxpag;
        $pagina=$request->getParameter('page',1);
        $this->pagina=$pagina;
       
        
        } else {
                if($opcion==1){
                    $this->redirect('@libros_filtro?titulo='.$titulo.'&autor='.$autor.'&opcion='.$opcion);
                }else {
                       if($opcion==2){
                      $c1 = new Criteria();
                      $c1->add(PublicationsPeer::ENABLED,1);
                      $c1->add(PublicationsPeer::PUBLICATIONS_TYPE_ID,2);
                      if($titulo!=""){
                            $c1->add(PublicationsPeer::TITLE, "%".$titulo."%", Criteria::LIKE);
                      }
                      if($autor!=""){
                            $c1->add(PublicationsPeer::AUTHOR, "%".$autor."%", Criteria::LIKE);
                        }

                        $c1->addDescendingOrderByColumn(PublicationsPeer::RELEASE_DATE);


                        $c1->addAscendingOrderByColumn(PublicationsPeer::CREATED_AT);

                        $pager = new sfPropelPager('Publications', 14);
                        $pager->setCriteria($c1);
                        $pager->setPage($request->getParameter('page',4 ));
                        $pager->init();
                        $this->pager = $pager;

                        $maxpag=$pager->getMaxPerPage();
                        $this->max=$maxpag;
                    $pagina=$request->getParameter('page',1);
                    $this->pagina=$pagina;
                    } else
                    {
                                $c2 = new Criteria();
                                $c2->add(PublicationsPeer::ENABLED,1);
                                $c2->add(PublicationsPeer::PUBLICATIONS_TYPE_ID,2);
                                if($titulo!=""){
                                    $c2->add(PublicationsPeer::TITLE, "%".$titulo."%", Criteria::LIKE);
                                }
                                if($autor!=""){
                                    $c2->add(PublicationsPeer::AUTHOR, "%".$autor."%", Criteria::LIKE);
                                }

                                $c2->addDescendingOrderByColumn(PublicationsPeer::RELEASE_DATE);

                                $c2->addAscendingOrderByColumn(PublicationsPeer::CREATED_AT);

                                $pager = new sfPropelPager('Publications', 14);
                                $pager->setCriteria($c2);
                                $pager->setPage($request->getParameter('page',4 ));
                                $pager->init();
                                $this->pager = $pager;

                                $maxpag=$pager->getMaxPerPage();
                                $this->max=$maxpag;
                                $pagina=$request->getParameter('page',1);
                                $this->pagina=$pagina;
                            
                                
                            }}}

    }
    public function executeLibros(sfWebRequest $request){
        $titulo=$request->getParameter('titulo');
        $autor=$request->getParameter('autor');
        $opcion=$request->getParameter('opcion');

          if($opcion==3)
                {
                $c = new Criteria();
                if($titulo!=""){
                    $c1->add(PublicationsPeer::TITLE, "%".$titulo."%", Criteria::LIKE);
                }
                if($autor!=""){
                    $c1->add(PublicationsPeer::AUTHOR, "%".$autor."%", Criteria::LIKE);
                }
                $c->add(PublicationsPeer::ENABLED,1);
                $c->addDescendingOrderByColumn(PublicationsPeer::RELEASE_DATE);
                $c->addAscendingOrderByColumn(PublicationsPeer::CREATED_AT);

                $pager = new sfPropelPager('Publications', 14);
                $pager->setCriteria($c);
                $pager->setPage($request->getParameter('page',4 ));
                $pager->init();
                $this->pager = $pager;

                $maxpag=$pager->getMaxPerPage();
                $this->max=$maxpag;
                $pagina=$request->getParameter('page',1);
                $this->pagina=$pagina;
                }else{

                    if($opcion==2){
            
                        $this->redirect('@revista_filtro?titulo='.$titulo.'&autor='.$autor.'&opcion='.$opcion);
                                }
                          else{
       
                               if($opcion==1){


                                $c = new Criteria();
                                $c->add(PublicationsPeer::ENABLED,1);
                                $c->add(PublicationsPeer::PUBLICATIONS_TYPE_ID,1);
                                if($titulo!=""){
                                    $c->add(PublicationsPeer::TITLE, "%".$titulo."%", Criteria::LIKE);
                                }
                                if($autor!=""){
                                    $c->add(PublicationsPeer::AUTHOR, "%".$autor."%", Criteria::LIKE);
                                }

                                $c->addDescendingOrderByColumn(PublicationsPeer::RELEASE_DATE);

                                $c->addAscendingOrderByColumn(PublicationsPeer::CREATED_AT);

                                $pager = new sfPropelPager('Publications', 14);
                                $pager->setCriteria($c);
                                $pager->setPage($request->getParameter('page', 1));
                                $pager->init();
                                $this->pager = $pager;

                                $maxpag=$pager->getMaxPerPage();
                                $this->max=$maxpag;
                                $pagina=$request->getParameter('page',1);
                                $this->pagina=$pagina;
                                }
                               else{
                                $c1 = new Criteria();
                                $c1->add(PublicationsPeer::ENABLED,1);
                                $c1->add(PublicationsPeer::PUBLICATIONS_TYPE_ID,1);
                                if($titulo!=""){
                                    $c1->add(PublicationsPeer::TITLE, "%".$titulo."%", Criteria::LIKE);
                                }
                                if($autor!=""){
                                    $c1->add(PublicationsPeer::AUTHOR, "%".$autor."%", Criteria::LIKE);
                                }

                                $c1->addDescendingOrderByColumn(PublicationsPeer::RELEASE_DATE);

                                $c1->addAscendingOrderByColumn(PublicationsPeer::CREATED_AT);

                                $pager = new sfPropelPager('Publications', 14);
                                $pager->setCriteria($c1);
                                $pager->setPage($request->getParameter('page', 1));
                                $pager->init();
                                $this->pager = $pager;

                                $maxpag=$pager->getMaxPerPage();
                                $this->max=$maxpag;
                                $pagina=$request->getParameter('page',1);
                                $this->pagina=$pagina;
                                }
                                }}
                                }


    public function executeDetalle(sfWebRequest $request){
           $id=$request->getParameter('id');
           $c=new Criteria();
           $c->add(PublicationsPeer::ID,$id);
           $publication = PublicationsPeer::doSelectOne($c);

           $x=new Noticias();
           $x->getDate('Y-m-d');

           $x=new Criteria();
           $x->add(ArticlesPeer::PUBLICATIONS_ID,$id);
           $lista=ArticlesPeer::doSelect($x);

           $x=new Publications();
           $x->getCreatedAt();
           $x->getReleaseDate();


           $this->publicacion=$publication;
           $this->lista=$lista;
    }






}